﻿using System;
namespace Q1
{
	public class question5
	{
		public question5()
		{
            List<Shape> shapes = new List<Shape>();
            for (int i = 0; i < 10; i++)
            {
                Shape shape = ShapeFactory.CreateShape();
                shapes.Add(shape);
            }

            double totalArea = 0;
            foreach (Shape shape in shapes)
            {
                if (shape.IsValid())
                {
                    totalArea += shape.Area;
                }
            }

            Console.WriteLine("总面积为：{0}", totalArea);
        }
	}
    class ShapeFactory
    {
        private static Random random = new Random();

        public static Shape CreateShape()
        {
            int shapeType = random.Next(3);
            switch (shapeType)
            {
                case 0:
                    double length = random.Next(1, 10);
                    double width = random.Next(1, 10);
                    Console.WriteLine("创建一个长为{0},宽为{0}的长方形", length, width);
                    return new Rectangle(length, width);
                case 1:
                    double sideLength = random.Next(1, 10);
                    Console.WriteLine("创建一个边长为{0}的正方形", sideLength);
                    return new Square(sideLength);
                case 2:
                    double side1 = random.Next(1, 10);
                    double side2 = random.Next(1, 10);
                    double side3 = random.Next(1, 10);
                    Console.WriteLine("创建一个三边分别为为{0},{0},{0}的三角形", side1, side2, side3);
                    return new Triangle(side1, side2, side3);
                default:
                    return null;
            }
        }
    }

}

